/* Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "zobjects_gtk.h"

ZlangInvokeFunction ZlangInvokeFunction_guifontchooserdialog_ModalOpenDialog_guiwindow_string;
int ZlangInvokeFunction_guifontchooserdialog_ModalOpenDialog_guiwindow_string( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guifontchooserdialog	*guifontchooserdialog_direct_prop = GetObjectDirectProperty(obj) ;
	struct ZlangObject				*in1 = GetInputParameterInLocalObjectStack(rt,1) ;
	struct ZlangObject				*in2 = GetInputParameterInLocalObjectStack(rt,2) ;
	struct ZlangObject				*out1 = GetOutputParameterInLocalObjectStack(rt,1) ;
	struct ZlangDirectProperty_guiwindow		*guiwindow_direct_prop = GetObjectDirectProperty(in1) ;
	struct ZlangDirectProperty_guiwidget_common	*guiwindow_common = (struct ZlangDirectProperty_guiwidget_common *)guiwindow_direct_prop ;
	char						*title = NULL ;
	
	CallRuntimeFunction_string_GetStringValue( rt , in2 , & title , NULL );

	guifontchooserdialog_direct_prop->gtk_dialog = gtk_font_chooser_dialog_new( title , GTK_WINDOW(guiwindow_common->gtk_widget) ) ;
	gtk_window_set_modal( GTK_WINDOW(guifontchooserdialog_direct_prop->gtk_dialog) , TRUE );
	gtk_font_chooser_set_preview_text( GTK_FONT_CHOOSER(guifontchooserdialog_direct_prop->gtk_dialog) , "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" );
	guifontchooserdialog_direct_prop->response = GtkDialogRun( rt , GTK_DIALOG(guifontchooserdialog_direct_prop->gtk_dialog) ) ;
	if( guifontchooserdialog_direct_prop->response == GTK_RESPONSE_ACCEPT )
		guifontchooserdialog_direct_prop->response = GTK_RESPONSE_OK ;
	if( guifontchooserdialog_direct_prop->response == GTK_RESPONSE_OK )
	{
		memset( guifontchooserdialog_direct_prop->font , 0x00 , sizeof(guifontchooserdialog_direct_prop->font) );
		strncpy( guifontchooserdialog_direct_prop->font , gtk_font_chooser_get_font(GTK_FONT_CHOOSER(guifontchooserdialog_direct_prop->gtk_dialog)) , sizeof(guifontchooserdialog_direct_prop->font)-1 );
		memset( guifontchooserdialog_direct_prop->font_family , 0x00 , sizeof(guifontchooserdialog_direct_prop->font_family) );
		strncpy( guifontchooserdialog_direct_prop->font_family , pango_font_family_get_name(gtk_font_chooser_get_font_family(GTK_FONT_CHOOSER(guifontchooserdialog_direct_prop->gtk_dialog))) , sizeof(guifontchooserdialog_direct_prop->font_family)-1 );
		memset( guifontchooserdialog_direct_prop->font_face , 0x00 , sizeof(guifontchooserdialog_direct_prop->font_face) );
		strncpy( guifontchooserdialog_direct_prop->font_face , pango_font_face_get_face_name(gtk_font_chooser_get_font_face(GTK_FONT_CHOOSER(guifontchooserdialog_direct_prop->gtk_dialog))) , sizeof(guifontchooserdialog_direct_prop->font_face)-1 );
		guifontchooserdialog_direct_prop->font_size = gtk_font_chooser_get_font_size(GTK_FONT_CHOOSER(guifontchooserdialog_direct_prop->gtk_dialog)) ;
	}
	CallRuntimeFunction_int_SetIntValue( rt , out1 , guifontchooserdialog_direct_prop->response );
	
	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_guifontchooserdialog_ModalOpenDialog_guiwindow_string_string;
int ZlangInvokeFunction_guifontchooserdialog_ModalOpenDialog_guiwindow_string_string( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guifontchooserdialog	*guifontchooserdialog_direct_prop = GetObjectDirectProperty(obj) ;
	struct ZlangObject				*in1 = GetInputParameterInLocalObjectStack(rt,1) ;
	struct ZlangObject				*in2 = GetInputParameterInLocalObjectStack(rt,2) ;
	struct ZlangObject				*in3 = GetInputParameterInLocalObjectStack(rt,3) ;
	struct ZlangObject				*out1 = GetOutputParameterInLocalObjectStack(rt,1) ;
	struct ZlangDirectProperty_guiwindow		*guiwindow_direct_prop = GetObjectDirectProperty(in1) ;
	struct ZlangDirectProperty_guiwidget_common	*guiwindow_common = (struct ZlangDirectProperty_guiwidget_common *)guiwindow_direct_prop ;
	char						*title = NULL ;
	char						*font = NULL ;
	
	CallRuntimeFunction_string_GetStringValue( rt , in2 , & title , NULL );
	CallRuntimeFunction_string_GetStringValue( rt , in3 , & font , NULL );

	guifontchooserdialog_direct_prop->gtk_dialog = gtk_font_chooser_dialog_new( title , GTK_WINDOW(guiwindow_common->gtk_widget) ) ;
	gtk_window_set_modal( GTK_WINDOW(guifontchooserdialog_direct_prop->gtk_dialog) , TRUE );
	gtk_font_chooser_set_preview_text( GTK_FONT_CHOOSER(guifontchooserdialog_direct_prop->gtk_dialog) , "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" );
	if( font && font[0] )
		gtk_font_chooser_set_font( GTK_FONT_CHOOSER(guifontchooserdialog_direct_prop->gtk_dialog) , font );
	guifontchooserdialog_direct_prop->response = GtkDialogRun( rt , GTK_DIALOG(guifontchooserdialog_direct_prop->gtk_dialog) ) ;
	if( guifontchooserdialog_direct_prop->response == GTK_RESPONSE_ACCEPT )
		guifontchooserdialog_direct_prop->response = GTK_RESPONSE_OK ;
	if( guifontchooserdialog_direct_prop->response == GTK_RESPONSE_OK )
	{
		memset( guifontchooserdialog_direct_prop->font , 0x00 , sizeof(guifontchooserdialog_direct_prop->font) );
		strncpy( guifontchooserdialog_direct_prop->font , gtk_font_chooser_get_font(GTK_FONT_CHOOSER(guifontchooserdialog_direct_prop->gtk_dialog)) , sizeof(guifontchooserdialog_direct_prop->font)-1 );
		memset( guifontchooserdialog_direct_prop->font_family , 0x00 , sizeof(guifontchooserdialog_direct_prop->font_family) );
		strncpy( guifontchooserdialog_direct_prop->font_family , pango_font_family_get_name(gtk_font_chooser_get_font_family(GTK_FONT_CHOOSER(guifontchooserdialog_direct_prop->gtk_dialog))) , sizeof(guifontchooserdialog_direct_prop->font_family)-1 );
		memset( guifontchooserdialog_direct_prop->font_face , 0x00 , sizeof(guifontchooserdialog_direct_prop->font_face) );
		strncpy( guifontchooserdialog_direct_prop->font_face , pango_font_face_get_face_name(gtk_font_chooser_get_font_face(GTK_FONT_CHOOSER(guifontchooserdialog_direct_prop->gtk_dialog))) , sizeof(guifontchooserdialog_direct_prop->font_face)-1 );
		guifontchooserdialog_direct_prop->font_size = gtk_font_chooser_get_font_size(GTK_FONT_CHOOSER(guifontchooserdialog_direct_prop->gtk_dialog)) ;
	}
	CallRuntimeFunction_int_SetIntValue( rt , out1 , guifontchooserdialog_direct_prop->response );
	
	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_guifontchooserdialog_GetFontAndSize;
int ZlangInvokeFunction_guifontchooserdialog_GetFontAndSize( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guifontchooserdialog	*guifontchooserdialog_direct_prop = GetObjectDirectProperty(obj) ;
	struct ZlangObject				*out1 = GetOutputParameterInLocalObjectStack(rt,1) ;
	
	CallRuntimeFunction_string_SetStringValue( rt , out1 , guifontchooserdialog_direct_prop->font , STRLEN_OF_STRING );
	
	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_guifontchooserdialog_GetFontFamily;
int ZlangInvokeFunction_guifontchooserdialog_GetFontFamily( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guifontchooserdialog	*guifontchooserdialog_direct_prop = GetObjectDirectProperty(obj) ;
	struct ZlangObject				*out1 = GetOutputParameterInLocalObjectStack(rt,1) ;
	
	CallRuntimeFunction_string_SetStringValue( rt , out1 , guifontchooserdialog_direct_prop->font , STRLEN_OF_STRING );
	
	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_guifontchooserdialog_GetFontFace;
int ZlangInvokeFunction_guifontchooserdialog_GetFontFace( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guifontchooserdialog	*guifontchooserdialog_direct_prop = GetObjectDirectProperty(obj) ;
	struct ZlangObject				*out1 = GetOutputParameterInLocalObjectStack(rt,1) ;
	
	CallRuntimeFunction_string_SetStringValue( rt , out1 , guifontchooserdialog_direct_prop->font_face , STRLEN_OF_STRING );
	
	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_guifontchooserdialog_GetFontSize;
int ZlangInvokeFunction_guifontchooserdialog_GetFontSize( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guifontchooserdialog	*guifontchooserdialog_direct_prop = GetObjectDirectProperty(obj) ;
	struct ZlangObject				*out1 = GetOutputParameterInLocalObjectStack(rt,1) ;
	
	CallRuntimeFunction_int_SetIntValue( rt , out1 , guifontchooserdialog_direct_prop->font_size/1024 );
	
	return 0;
}

ZlangCreateDirectPropertyFunction ZlangCreateDirectProperty_guifontchooserdialog;
void *ZlangCreateDirectProperty_guifontchooserdialog( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guifontchooserdialog	*guifontchooserdialog_prop = NULL ;
	
	guifontchooserdialog_prop = (struct ZlangDirectProperty_guifontchooserdialog *)ZLMALLOC( sizeof(struct ZlangDirectProperty_guifontchooserdialog) ) ;
	if( guifontchooserdialog_prop == NULL )
	{
		SET_RUNTIME_ERROR( rt , RUNTIME_ERROR , ZLANG_ERROR_ALLOC , "alloc memory for entity" )
		return NULL;
	}
	memset( guifontchooserdialog_prop , 0x00 , sizeof(struct ZlangDirectProperty_guifontchooserdialog) );
	
	return guifontchooserdialog_prop;
}

ZlangDestroyDirectPropertyFunction ZlangDestroyDirectProperty_guifontchooserdialog;
void ZlangDestroyDirectProperty_guifontchooserdialog( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guifontchooserdialog	*guifontchooserdialog_direct_prop = GetObjectDirectProperty(obj) ;
	
	ZLFREE( guifontchooserdialog_direct_prop );
	
	return;
}

ZlangSummarizeDirectPropertySizeFunction ZlangSummarizeDirectPropertySize_guifontchooserdialog;
void ZlangSummarizeDirectPropertySize_guifontchooserdialog( struct ZlangRuntime *rt , struct ZlangObject *obj , size_t *summarized_obj_size , size_t *summarized_direct_prop_size )
{
	SUMMARIZE_SIZE( summarized_direct_prop_size , sizeof(struct ZlangDirectProperty_guifontchooserdialog) )
	return;
}

static struct ZlangDirectFunctions direct_funcs_guifontchooserdialog =
	{
		ZLANG_OBJECT_guifontchooserdialog , /* char *ancestor_name */
		
		ZlangCreateDirectProperty_guifontchooserdialog , /* ZlangCreateDirectPropertyFunction *create_entity_func */
		ZlangDestroyDirectProperty_guifontchooserdialog , /* ZlangDestroyDirectPropertyFunction *destroy_entity_func */
		
		NULL , /* ZlangFromCharPtrFunction *from_char_ptr_func */
		NULL , /* ZlangToStringFunction *to_string_func */
		NULL , /* ZlangFromDataPtrFunction *from_data_ptr_func */
		NULL , /* ZlangGetDataPtrFunction *get_data_ptr_func */
		
		NULL , /* ZlangOperatorFunction *oper_PLUS_func */
		NULL , /* ZlangOperatorFunction *oper_MINUS_func */
		NULL , /* ZlangOperatorFunction *oper_MUL_func */
		NULL , /* ZlangOperatorFunction *oper_DIV_func */
		NULL , /* ZlangOperatorFunction *oper_MOD_func */
		
		NULL , /* ZlangUnaryOperatorFunction *unaryoper_NEGATIVE_func */
		NULL , /* ZlangUnaryOperatorFunction *unaryoper_NOT_func */
		NULL , /* ZlangUnaryOperatorFunction *unaryoper_BIT_REVERSE_func */
		NULL , /* ZlangUnaryOperatorFunction *unaryoper_PLUS_PLUS_func */
		NULL , /* ZlangUnaryOperatorFunction *unaryoper_MINUS_MINUS_func */
		
		NULL , /* ZlangCompareFunction *comp_EGUAL_func */
		NULL , /* ZlangCompareFunction *comp_NOTEGUAL_func */
		NULL , /* ZlangCompareFunction *comp_LT_func */
		NULL , /* ZlangCompareFunction *comp_LE_func */
		NULL , /* ZlangCompareFunction *comp_GT_func */
		NULL , /* ZlangCompareFunction *comp_GE_func */
		
		NULL , /* ZlangLogicFunction *logic_AND_func */
		NULL , /* ZlangLogicFunction *logic_OR_func */
		
		NULL , /* ZlangLogicFunction *bit_AND_func */
		NULL , /* ZlangLogicFunction *bit_XOR_func */
		NULL , /* ZlangLogicFunction *bit_OR_func */
		NULL , /* ZlangLogicFunction *bit_MOVELEFT_func */
		NULL , /* ZlangLogicFunction *bit_MOVERIGHT_func */
		
		ZlangSummarizeDirectPropertySize_guifontchooserdialog , /* ZlangSummarizeDirectPropertySizeFunction *summarize_direct_prop_size_func */
	} ;

ZlangImportObjectFunction ZlangImportObject_guifontchooserdialog;
struct ZlangObject *ZlangImportObject_guifontchooserdialog( struct ZlangRuntime *rt )
{
	struct ZlangObject	*obj = NULL ;
	struct ZlangFunction	*func = NULL ;
	int			nret = 0 ;
	
	nret = ImportObject( rt , & obj , ZLANG_OBJECT_guifontchooserdialog , & direct_funcs_guifontchooserdialog , sizeof(struct ZlangDirectFunctions) , NULL ) ;
	if( nret )
	{
		SET_RUNTIME_ERROR( rt , RUNTIME_ERROR , ZLANG_ERROR_LINK_FUNC_TO_ENTITY , "import object to global objects heap" )
		return NULL;
	}
	
	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guifontchooserdialog_ModalOpenDialog_guiwindow_string , ZLANG_OBJECT_int , "ModalOpenDialog" , ZLANG_OBJECT_guiwindow,NULL , ZLANG_OBJECT_string,NULL , NULL ) ;
	if( func == NULL )
		return NULL;
	
	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guifontchooserdialog_ModalOpenDialog_guiwindow_string_string , ZLANG_OBJECT_int , "ModalOpenDialog" , ZLANG_OBJECT_guiwindow,NULL , ZLANG_OBJECT_string,NULL , ZLANG_OBJECT_string,NULL , NULL ) ;
	if( func == NULL )
		return NULL;
	
	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guifontchooserdialog_GetFontAndSize , ZLANG_OBJECT_string , "GetFontAndSize" , NULL ) ;
	if( func == NULL )
		return NULL;
	
	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guifontchooserdialog_GetFontFamily , ZLANG_OBJECT_string , "GetFontFamily" , NULL ) ;
	if( func == NULL )
		return NULL;
	
	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guifontchooserdialog_GetFontFace , ZLANG_OBJECT_string , "GetFontFace" , NULL ) ;
	if( func == NULL )
		return NULL;
	
	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guifontchooserdialog_GetFontSize , ZLANG_OBJECT_int , "GetFontSize" , NULL ) ;
	if( func == NULL )
		return NULL;
	
	return obj ;
}

